﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using DotNet.Business;
using DotNet.Model;
using DotNet.Common;
using System.IO;
public partial class Admin_EditPower : System.Web.UI.Page
{
    PowerBll pBll = new PowerBll();
    power pModel = new power();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["state"]!=null)
            {
                int pid = Convert.ToInt32(Request.QueryString["pid"].ToString());
                string state = Request.QueryString["state"].ToString();
                switch (state.Trim())
                {
                    case "edit":
                        this.pid_hid.Value = pid.ToString();
                        this.pageIndex_hid.Value = Request.QueryString["CurrentIndex"];
                        loadPower(pid);
                        break;
                    case "update":
                        update(pid);
                        break;
                    default:
                        break;
                }
            }
        }

    }


    #region 给html赋值---郑同飞
    public void loadPower(int pid) 
    {
        pModel = pBll.GetModel(pid);
        this.powerName.Value = pModel.Powername;
        this.demoName.Value = pModel.DemoName;
        this.demoInfo.Value = pModel.Demoinfo;
        this.demoPage_hid.Value = pModel.Powerpage;
    

    }
    #endregion

    #region 获得后台管理的页面，本页面有程序员操作
    /// <summary>
    /// 获得后台管理的页面，本页面有程序员操作
    /// </summary>
    /// <returns></returns>
    public string pageHtml(string demoPage)
    {

        string pageStr = "";
        string[] pages = Directory.GetFiles(Server.MapPath(@"~/Admin/"));
        foreach (string page in pages)
        {
            if (Path.GetFileName(page) == demoPage)
            {

                if (page.EndsWith(".aspx"))
                {
                    
                        pageStr += "<input id=\"Radio1\" type=\"radio\" checked=\"checked\" value='" + Path.GetFileName(page) + "' name=\"page\">" + Path.GetFileName(page) + "</input>" + "<br>";
                }
            }
            else 
            {
                if (page.EndsWith(".aspx"))
                {
                   
                        pageStr += "<input id=\"Radio1\" type=\"radio\" value=" + Path.GetFileName(page) + " name=\"page\">" + Path.GetFileName(page) + "</input>" + "<br>";
                }
            }
        }
        return pageStr;

    }
    #endregion

    #region 编辑保存---郑同飞
    /// <summary>
    /// 编辑保存---郑同飞
    /// </summary>
    /// <param name="pid"></param>
    public void update(int pid) 
    {
        pModel.Powername =Request.Form["powerName"].ToString();
        pModel.DemoName = Request.Form["demoName"].ToString();
        pModel.Demoinfo = Request.Form["demoInfo"].ToString();
        pModel.Powerpage = Request.Form["page"].ToString();
        pModel.PowerId=pid;
    
        if (pBll.Update(pModel))
        {
            Response.Write("1");
            Response.End();
        }
    }
    #endregion
}
